package com.ruoyi.develop.factory.factoryProduceSale.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.develop.factory.factoryProduceSale.domain.FactoryProduceSale;
import com.ruoyi.develop.factory.factoryProduceSale.service.IFactoryProduceSaleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产订单和产品关联Controller
 * @author lmm
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/factoryProduceSale/factoryProduceSale")
public class FactoryProduceSaleController extends BaseController {
    @Autowired
    private IFactoryProduceSaleService factoryProduceSaleService;

    /**
     * 查询生产订单和产品关联列表
     */
    @PreAuthorize("@ss.hasPermi('develop:FactoryProduceSale:query')")
    @GetMapping("/list")
    public TableDataInfo list(FactoryProduceSale entity) {
        startPage();
        List<FactoryProduceSale> list = factoryProduceSaleService.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出生产订单和产品关联列表
     */
    @PreAuthorize("@ss.hasPermi('develop:FactoryProduceSale:export')")
    @Log(title = "生产订单和产品关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FactoryProduceSale entity) {
        List<FactoryProduceSale> list = factoryProduceSaleService.selectList(entity);
        ExcelUtil<FactoryProduceSale> util = new ExcelUtil<FactoryProduceSale>(FactoryProduceSale. class);
        util.exportExcel(response, list, "生产订单和产品关联数据");
    }

    /**
     * 获取生产订单和产品关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:FactoryProduceSale:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(factoryProduceSaleService.selectById(id));
    }

    /**
     * 新增生产订单和产品关联
     */
    @PreAuthorize("@ss.hasPermi('develop:FactoryProduceSale:add')")
    @Log(title = "生产订单和产品关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FactoryProduceSale entity) {
        return toAjax(factoryProduceSaleService.insert(entity));
    }

    /**
     * 修改生产订单和产品关联
     */
    @PreAuthorize("@ss.hasPermi('develop:FactoryProduceSale:edit')")
    @Log(title = "生产订单和产品关联", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FactoryProduceSale entity) {
        return toAjax(factoryProduceSaleService.update(entity));
    }

    /**
     * 删除生产订单和产品关联
     */
    @PreAuthorize("@ss.hasPermi('develop:FactoryProduceSale:remove')")
    @Log(title = "生产订单和产品关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(factoryProduceSaleService.deleteByIds(ids));
    }
}
